<?php

namespace Api\Member\AuthManager;

use Dingo\Api\Facade\API as DingoApi;

class Auth
{
    /**
     * 构造方法
     */
    public function __construct($authProviderKey)
    {
        $this->authProviderKey = $authProviderKey;
    }

    /**
     * 获取已登陆账户实例
     *
     * @return void
     */
    private function auth()
    {
        $auth = DingoApi::user();
        if ($auth['authProviderKey'] === $this->authProviderKey) {
            return $auth['account'];
        }
        else {
            error('forbidden');
        }
    }

    /**
     * 读取账户对象属性
     *
     * @return void
     */
    private function getId()
    {
        return $this->auth()->id;
    }

    /**
     * 魔术方法
     */
    public function __get($name)
    {
        $getMethod = camel_case('get_'.$name);
        return $this->$getMethod();
    }

}
